package com.javasm.controller;


import com.javasm.common.http.AxiosResult;
import com.javasm.common.page.PageResult;
import com.javasm.controller.base.BaseController;
import com.javasm.domin.criteria.AftersaleOutDepotCriteria;
import com.javasm.domin.entity.AftersaleOutDepot;
import com.javasm.domin.vo.AftersaleOutDepotVo;
import com.javasm.service.AftersaleOutDepotService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author ljy
 * @since 2022-01-16
 */
@RestController
@RequestMapping("aftersale-out-depot")
@RequiredArgsConstructor
public class AftersaleOutDepotController extends BaseController {

    private final AftersaleOutDepotService aftersaleOutDepotService;

    /**
     * 查询所有
     * @param aftersaleOutDepotCriteria
     * @return
     */
    @GetMapping("list")
    public AxiosResult<PageResult<AftersaleOutDepotVo>> list(AftersaleOutDepotCriteria aftersaleOutDepotCriteria) {
        PageResult<AftersaleOutDepotVo> list = aftersaleOutDepotService.selectByPageCriteria(aftersaleOutDepotCriteria);
        return AxiosResult.success(list);
    }

    /**
     * 根据id删除单条数据
     * @param id
     * @return
     */
    @DeleteMapping("deleteById/{id}")
    public AxiosResult<Void> deleteById(@PathVariable Long id) {
        return toAxios(aftersaleOutDepotService.deleteById(id));
    }

    /**
     * 根据id查询
     * @param id
     * @return
     */
    @GetMapping("{id}")
    public AxiosResult<AftersaleOutDepot> findById(@PathVariable Long id) {
//        AftersaleOutDepotVo byId = aftersaleOutDepotService.castToVo(id);
        AftersaleOutDepot byId = aftersaleOutDepotService.getById(id);
        return AxiosResult.success(byId);
    }

    /**
     * 新增
     * @param aftersaleOutDepot
     * @return
     */
    @PostMapping("insert")
    public AxiosResult<Void> insert(@RequestBody AftersaleOutDepot aftersaleOutDepot) {
        return toAxios(aftersaleOutDepotService.save(aftersaleOutDepot));
    }

    /**
     * 修改
     * @param aftersaleOutDepot
     * @return
     */
    @PutMapping("update")
    public AxiosResult<Void> update(@RequestBody AftersaleOutDepot aftersaleOutDepot) {
        return toAxios(aftersaleOutDepotService.update(aftersaleOutDepot));
    }

    /**
     * 批量删除
     * @param ids
     * @return
     */
    @DeleteMapping("batch/{ids}")
    public AxiosResult<Void> batchDeleteByIds(@PathVariable List<Long> ids) {
        return toAxios(aftersaleOutDepotService.batchDeleteByIds(ids));
    }
}
